﻿var keyVaule = request('keyVaule');
var bootstrap = function ($, learun) {
    "use strict";

    $.lrSetForm(config.base_server() + 'files/list?folderId=' + keyVaule + '&access_token=' + config.getToken().access_token, function (data) {
        for (var i = 0, l = data.length; i < l; i++) {
            $('#lr_form_file_queue .lr-form-file-queue-bg').hide();
            var item = data[i];
            var $item = $('<div class="lr-form-file-queue-item" id="lr_filequeue_' + item.id + '" ></div>');
            $item.append('<div class="lr-file-image"><img src="/assets/plugins/images/filetype/' + item.ext + '.png"></div>');


            $item.append('<div>');
            $item.append('<span class="lr-file-name">' + item.name + '(' + learun.countFileSize(item.size) + ')</span>');
            $item.append('<span class="lr-file-time">' + item.updateTime + '(' + item.updateUsername + ')</span>');
            $item.append('</div>');


            $item.append('<div class="lr-tool-bar"><i class="fa fa-eye" title="预览"  data-value="' + item.id + '" ></i><i class="fa fa-cloud-download" title="下载"  data-value="' + item.id + '" ></i></div>');



            $item.find('.lr-tool-bar .fa-cloud-download').on('click', function () {
                var fileId = $(this).attr('data-value');
                DownFile(fileId);
            });
            $item.find('.lr-tool-bar .fa-eye').on('click', function () {
                var fileId = $(this).attr('data-value');
                openViewForm(fileId);
            });
            $('#lr_form_file_queue_list').append($item);
        }
    });
    // 下载文件
    var DownFile = function (fileId) {
        learun.download({
            url: config.base_server() + 'files/download?id=' + fileId + '&access_token=' + config.getToken().access_token,
            param: {fileId: fileId},
            method: 'POST'
        });
    }
    //预览文件
    var openViewForm = function (fileId) {
        learun.layerForm({
            id: 'PreviewForm',
            title: '文件预览',
            url: config.webportal_server + 'pages/utility/previewFile.html?keyVaule=' + fileId + '&access_token=' + config.getToken().access_token,
            width: 1080,
            height: 850,
            btn: null
        });
    }

    $('#lr_form_file_queue').lrscroll();
}
